const app = getApp();
const https = require('../../utils/https');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    tabIndex: 0,
    obtainList: [],
    consumeList: []
  },
  tabTap(e) {
    this.setData({
      tabIndex: e.currentTarget.dataset.index
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that = this,
      login_status = wx.getStorageSync('login_status');
    if (!login_status || login_status <= 0) {
      wx.showLoading({
        title: '请先进行登陆',
      })
      setTimeout(() => {
        wx.hideLoading({
          success: (res) => {
            wx.navigateTo({
              url: '/pages/grant/grant',
            })
          },
        })
      }, 1500);
    } else {
      that.getUserInfo();
      that.getIntegralLog();
    }
  },

  // 获取用户信息
  getUserInfo: function () {
    var that = this,
      user_id = wx.getStorageSync('user_id');
    if (user_id > 0) {
      https.post('getUserInfo', {
        user_id: user_id
      }, false, '加载中').then(res => {
        that.setData({
          user_info: res
        })
      })
    }
  },
  /**
   * @xk 获取积分明细 分为进账&出账
   * @param {*} res 
   */
  getIntegralLog: function(res){
    var that = this,
        user_id = wx.getStorageSync('user_id');
    https.post('getIntegralLog',{user_id: user_id},false,'加载中').then(res=>{
      that.setData({
        inc_list: res.inc_list,
        dec_list: res.dec_list
      })
    })
  },
  getIntegral: function(res){
    wx.navigateTo({
      url: '/pages/magic_explain/explain',
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.onShow();
  },
})